package cn.xfdzx.android.apps.shop.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.HomeSearchRetailGoodsBean;
import cn.xfdzx.android.apps.shop.bean.HotSearchRetailBean;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;

/**
 * Creator: zf.
 * Date: 2020/9/24.
 * Description:零售--热门搜索.
 */
public class SearchHotRetailListAdapter extends BaseQuickAdapter<HotSearchRetailBean.DataBean, BaseViewHolder>  {
    private List<HotSearchRetailBean.DataBean> hotSearch;
    private OnItemOnClickListener onItemOnClickListener;
    public SearchHotRetailListAdapter(@Nullable List<HotSearchRetailBean.DataBean> data) {
        super(R.layout.item_searchhot_retail, data);
        this.hotSearch = data;
    }

    @Override
    public void setData(int index, @NonNull HotSearchRetailBean.DataBean data) {
        super.setData(index, data);
    }


    @Override
    protected void convert(final BaseViewHolder viewHolder, final HotSearchRetailBean.DataBean date) {
        TextView tv_title = viewHolder.getView(R.id.tv_title);
        ImageView img_hot = viewHolder.getView(R.id.img_hot);
        TextView tv_lablecu = viewHolder.getView(R.id.tv_lablecu);


        if(EmptyUtil.isNotEmpty(date)){
            tv_title.setText(date.getName());
            // 是否热搜  1 => 是  0 => 否
            if (date.getIs_hot().equals("0")){
                img_hot.setVisibility(View.GONE);
            }else {
                img_hot.setVisibility(View.VISIBLE);
                if ( date.getIs_activity().equals("1")){
                    tv_lablecu.setVisibility(View.VISIBLE);
                    img_hot.setVisibility(View.GONE);
                }
            }

            // 是否是活动  1 => 是  0 => 否
            if (date.getIs_activity().equals("0")){
                tv_lablecu.setVisibility(View.GONE);
            }else {
                tv_lablecu.setVisibility(View.VISIBLE);
                img_hot.setVisibility(View.GONE);
            }

        }



        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemOnClickListener.onItemClick(viewHolder.getLayoutPosition(),date);
            }
        });
    }
    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<HotSearchRetailBean.DataBean> list){
        super.replaceData(list);
        this.hotSearch = list;
    }

    public void setItemClickListener(OnItemOnClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemOnClickListener {
        void onItemClick(int position,HotSearchRetailBean.DataBean date);
    }
}
